package me.tuyou.activiti.taskService;

import me.tuyou.activiti.Base;
import org.activiti.engine.runtime.Execution;
import org.activiti.engine.runtime.ProcessInstance;
import org.junit.Test;

import java.util.HashMap;

public class ReceiveTaskTest extends Base {

    @Test
    public void deploy() {
        repositoryService.createDeployment()
                .addClasspathResource("ReceiveTaskTest.bpmn")
                .name("接收任务测试")
                .deploy();
    }

    @Test
    public void startInstance() {
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("ReceiveTaskTest");
        System.out.println("流程id：" + processInstance.getId());
    }

    /**
     * 汇总销售总额
     */
    @Test
    public void generateReport() {
        Execution execution = runtimeService.createExecutionQuery()
                .processInstanceId("152501")
                .activityId("汇总当日销售额")
                .singleResult();
        HashMap<String, Object> variables = new HashMap<>();
        variables.put("当日销售额", 10000);

        runtimeService.signal(execution.getId(), variables);
        checkProcessStop(execution.getProcessInstanceId());
    }

    /**
     * 发送短信
     */
    @Test
    public void sendMessage() {
        Execution execution = runtimeService.createExecutionQuery()
                .processInstanceId("152501")
                .activityId("给总经理发短信")
                .singleResult();
        int total = (int)runtimeService.getVariable(execution.getId(), "当日销售额");
        System.out.println("给经理发短信，今日销售总额：" + total);

        runtimeService.signal(execution.getId());
        checkProcessStop(execution.getProcessInstanceId());
    }
}
